@extends('adminDialog')
@section('content')
    <form action="{{url('admin/rbac/edituser/'.$user->id)}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table" style="overflow-y: scroll;">
            <table width="100%">
                <tbody>
                <tr>
                    <th>
                        <label for="title">名称<span class="red">*</span></label>
                    </th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_6"  value="{{$user->name}}"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="title">密码<span class="red">*</span></label>
                    </th>
                    <td>
                        <input type="password" name="password" id="password" class="input length_6"  value="{{$user->password}}"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="title">昵称</label>
                    </th>
                    <td>
                        <input type="text" name="nickName" id="nickName" class="input length_6"  value="{{$user->nickName}}"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="title">电话</label>
                    </th>
                    <td>
                        <input type="text" name="mobile" id="mobile" class="input length_6"  value="{{$user->mobile}}"/>
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="title">角色<span class="red">*</span></label>
                    </th>
                    <td class="tdradio">
                        @foreach($roles as $key=>$role)
                            <input type="radio" name="role"
                                   {{-- 该用户有这个权限则选中 --}}
                                   @if($user->hasRole($role->name)) checked="checked" @endif
                                   {{--如果是注册用户不能修改成其他角色--}}
                                   @if($user->hasRole('user'))
                                   disabled="disabled"
                                   {{--如果是非注册用户不能修改成注册用户--}}
                                   @elseif( in_array($role->name, ['user']) )
                                   disabled="disabled"
                                   @endif

                                   id="{{$role->name}}" class="input"  value="{{$role->name}}"/>
                            <label for="{{$role->name}}">{{$role->display_name}}</label>
                        @endforeach
                    </td>
                </tr>
                @if($user->hasRole('user'))
                    <tr id="serviceGroup">
                        <th>
                            <label for="title">分配购务<span class="red">*</span></label>
                        </th>
                        <td  class="tdradio">
                            @foreach($service as $key=>$value)
                                <input type="radio" name="salesmanId"
                                       @if($user->salesmanId == $value->id) checked="checked" @endif
                                       id="{{$value->id}}" class="input"  value="{{$value->id}}"/>
                                <label for="{{$value->id}}">{{$value->name}}({{$value->nickName}})</label>
                            @endforeach
                        </td>
                    </tr>
                @endif
                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style type="text/css">
        .body_none {
            width: 720px;
        }
        table th{ width: 15%; }
    </style>
@stop

@section('js')
    @parent
    @include('UEditor::head')
    <script src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
    <script>
        var ue = UE.getEditor('container', {
            initialFrameWidth: 600, initialFrameHeight: 300, autoHeightEnabled: false, toolbars: [
                ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
                ['link', 'simpleupload', 'insertimage']
            ]
        });
        ue.ready(function () {
            ue.execCommand('serverparam', '_token', "{{ csrf_token() }}");//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
        });
    </script>
    <script>
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pic', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('upimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'dir': '{{$type}}'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        tips(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        if (response.state == 'success') {
                            __type = "{{$type}}";
                            $('.pickfiles img').attr('src', '{!! url("img/'+__type+'-' + response.id + '/290-165") !!}');
                            $('.pickfiles input').val(response.id);
                        } else {
                            tips(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });

        $("input[name=role]").on('click', function(){
            if(['admin','service','salesman'].indexOf($(this).val())>-1){
                $('#serviceGroup').hide();
            }else{
                $("#serviceGroup").show();
            }
        });
    </script>
@stop
